<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">

    $(document).ready(function () {
        loadAlienationData();
    });

    function loadAlienationData() {
        $('#alienationMethod').val($('#alienationType').val());

        if ($('#alienationType').val() == 0) {
            $("#alienation-details").hide();
            $("#commentOnAlienation").hide();
            //   $("#alienationDocuments").hide();

        } else {
            $("#alienation-details").show();
            var landId = '<s:property value="landId"/>';
            var url = '${"loadInitAlienationPage.do?landId=' + landId + '"}';
            $.post(url, $('#load-form').serialize(), function (data) {
                $("#alienation-details").html(data);
                if ($('#alienationType').val() == unalienated) {
                    $("#commentOnAlienation").hide();
                    // $("#alienationDocuments").hide();
                } else {
                    $("#commentOnAlienation").show();
                    //  $("#alienationDocuments").show();
                }
                $('#tabs').tabs();
            });
        }
    }

    //todo: move to landalienationinformation.jsp
    function validateFields() {
        if ($('#alienationType').val() != unalienated) {
            $("#referenceNo").rules("add", {required:true, messages:{
                required:$('#this_field_required').val()}
            });
            //TODO: Do not hard code AM here, pass custom message in order to support tri lingual
            if ($('#alienationType').val() != 5 && $('#alienationType').val() != 6) {
                $("#name").rules("add", {required:true, messages:{
                    required:$('#this_field_required').val()}
                }); //TODO: name of the holder need to be renamed. Dont use term "name"
                $("#nic").rules("add", {NICNo:true, messages:{
                    NICNo:$('#pls_enter_valid_nic_no').val()}
                });
                $("#mobile").rules("add", {phoneNo:true, messages:{
                    phoneNo:$('#pls_enter_valid_phone_no').val()}
                });
                $("#landPhone").rules("add", {phoneNo:true, messages:{
                    phoneNo:$('#pls_enter_valid_phone_no').val()}
                });
                $("#email").rules("add", {email:true, messages:{
                    email:$('#pls_enter_valid_email').val()}
                });
                $("#fax").rules("add", {phoneNo:true, messages:{
                    phoneNo:$('#pls_enter_valid_fax_no').val()}
                });
                $("#dateOfBirth").rules("add", {isDateFormated:true,ageValidate:true, messages:{
                    ageValidate:$('#pls_enter_valid_age').val()}
                });
                $("#issueDate").rules("add", {isDateFormated:true});
            }
            if ($('#alienationType').val() == 2) {
                $("#minHectareId").rules("add", {number:true, messages:{
                    number:$('#pls_enter_valid_no').val()}
                });
                $("#minAcreId").rules("add", {number:true, messages:{
                    number:$('#pls_enter_valid_no').val()}
                });
                $("#minRoodsId").rules("add", {number:true, messages:{
                    number:$('#pls_enter_valid_no').val()}
                });
                $("#minPerchesId").rules("add", {number:true, messages:{
                    number:$('#pls_enter_valid_no').val()}
                });
                $("#minFraction").rules("add", {number:true, messages:{
                    number:$('#pls_enter_valid_no').val()}
                });
                $("#mortgagePeriodInYears").rules("add", {digits:true, messages:{
                    digits:$('#pls_enter_valid_no').val()}
                });
                $("#mortgagePeriodInMonths").rules("add", {digits:true, messages:{
                    digits:$('#pls_enter_valid_no').val()}
                });
                $("#issueDate").rules("add", {isDateFormated:true});
                $("#folioDate").rules("add", {isDateFormated:true});
                $("#startedDate").rules("add", {isDateFormated:true});
            }
            if ($('#alienationType').val() == 3) {
                $("#valuation").rules("add", {positiveNumber:true, messages:{
                    positiveNumber:$('#pls_enter_valid_no').val()}
                });
                $("#rental").rules("add", {positiveNumber:true, messages:{
                    positiveNumber:$('#pls_enter_valid_no').val()}
                });
                $("#issueDate").rules("add", {isDateFormated:true});
                $("#occupier-dob'+occupierIndex+'").rules("add", {isDateFormated:true});
            }
            if ($('#alienationType').val() == 4) {
                //$("#issueDate").rules("add", "required");
                $("#leasePeriod").rules("add", {required:true,digits:true, messages:{
                    required:$('#this_field_required').val(),
                    digits:$('#pls_enter_valid_no').val()}
                });
                $("#leaseDiagramNo").rules("add", {required:true, messages:{
                    required:$('#this_field_required').val()}
                });
                $("#developed-value").rules("add", {positiveNumber:true, messages:{
                    positiveNumber:$('#pls_enter_valid_no').val()}
                });
                $("#commercial-value").rules("add", {positiveNumber:true, messages:{
                    positiveNumber:$('#pls_enter_valid_no').val()}
                });
                $("#undeveloped-value").rules("add", {positiveNumber:true, messages:{
                    positiveNumber:$('#pls_enter_valid_no').val()}
                });
                $("#leaseArrearsFromYear").rules("add", {digits:true, messages:{
                    digits:$('#pls_enter_valid_no').val()}
                });
                $("#leaseArrearsToYear").rules("add", {digits:true, messages:{
                    digits:$('#pls_enter_valid_no').val()}
                });
                $("#amend-period").rules("add", {digits:true, messages:{
                    digits:$('#pls_enter_valid_no').val()}
                });
                $("#mortgagePeriodInYears").rules("add", {digits:true, messages:{
                    digits:$('#pls_enter_valid_no').val()}
                });
                $("#mortgagePeriodInMonths").rules("add", {digits:true, messages:{
                    digits:$('#pls_enter_valid_no').val()}
                });
                $("#issueDate").rules("add", {isDateFormated:true});
                $("#folioDate").rules("add", {isDateFormated:true});
                $("#startedDate").rules("add", {isDateFormated:true});
            }
            if ($('#alienationType').val() == 7) {
                $("#valuation").rules("add", {positiveNumber:true, messages:{
                    positiveNumber:$('#pls_enter_valid_no').val()}
                });
                $("#issueDate").rules("add", {isDateFormated:true});
                $("#folioDate").rules("add", {isDateFormated:true});
                $("#paymentDate").rules("add", {isDateFormated:true});
            }
            if ($('#alienationType').val() == 5) {
                $("#mobile").rules("add", {phoneNo:true, messages:{
                    phoneNo:$('#pls_enter_valid_phone_no').val()}
                });
                $("#landPhone").rules("add", {phoneNo:true, messages:{
                    phoneNo:$('#pls_enter_valid_phone_no').val()}
                });
                $("#email").rules("add", {email:true, messages:{
                    email:$('#pls_enter_valid_email').val()}
                });
                $("#fax").rules("add", {phoneNo:true, messages:{
                    phoneNo:$('#pls_enter_valid_fax_no').val()}
                });
                $("#issueDate").rules("add", {isDateFormated:true});
            }
            if ($('#alienationType').val() == 6) {
                $("#issueDate").rules("add", {isDateFormated:true});
                $("#folioDate").rules("add", {isDateFormated:true});
            }
        }
    }
</script>
<%--<s:form method="POST" enctype="multipart/form-data">--%>
<h2><s:label value="%{getText('alienation_info.label')}"/></h2>
<fieldset>
    <table class="width-100">
        <tr id="alienation-type">
            <td><s:label value="%{getText('alienation_method.label')}"/></td>
            <td colspan="3"><s:select list="alienationTypeList" name="alienationType"
                                      id="alienationType"
                                      headerKey="0"
                                      headerValue="%{getText('select.label')}"
                                      onchange="loadAlienationData();" cssClass="width-250-px"/>

            </td>
        </tr>
    </table>
    <table class="width-100" id="alienation-details">

    </table>
    <s:hidden name="holder.id"/>
    <table class="width-100" id="commentOnAlienation">
        <tr>
            <td><s:label value="%{getText('comment_about_alienation.label')}"/></td>
            <td colspan="3"><s:textarea id="alienationComment" name="alienation.alienationComment"
                                        cssClass="width-595-px" rows="1"/></td>
        </tr>
    </table>

</fieldset>
<%--</s:form>--%>
